package com.sayimo.maker.base.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.sayimo.framework.exception.DaoException;
import com.sayimo.framework.exception.ServiceException;
import com.sayimo.maker.base.dao.EmsListDao;
import com.sayimo.maker.base.service.EmsService;
import com.sayimo.maker.base.vo.EmsList;
import com.sayimo.maker.commons.Constant;

/**
 * @Project: schoolmallapi-trunk2.0
 * @ClassName: EmsServiceImpl
 * @Description: 
 * @author:	chenpy
 * @date:	2016年7月7日
 * @version 1.0.0
 */
@Service(value="emsService")
public class EmsServiceImpl implements EmsService{
	
	@Resource(name="emsListDao")
	private EmsListDao emsListDao;
	
	private static Log logger = LogFactory.getLog(EmsServiceImpl.class);

	/** 
	  * @package com.sayimo.school.mall.module.base.service
	  * @author chenpy
	  * @Title:  
	  * @Description: 获取EMS列表
	  * @param 
	  * @throws 
	  * @return Map<String,Object>
	  * @date 2016年7月7日
	  */ 
	public Map<String, Object> getAllEms() throws ServiceException {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			List<EmsList> emsList = emsListDao.queryEmsList();
			Map datas[] = new HashMap[emsList.size()];
			if (CollectionUtils.isNotEmpty(emsList)) {
				int index = 0;
				for (EmsList emsList2 : emsList) {
					Map map = new HashMap();
					map.put("id", emsList2.getId());
					map.put("emsName", emsList2.getEmsName());
					datas[index] = map;
					index += 1;
				}
			}
			
			resultMap.put(Constant.STATUS, Constant.STATUS_SUCCESS);
			Map<String, Object> dataObject = new HashMap<>();
			dataObject.put("emsList", datas);
			resultMap.put(Constant.DATA, dataObject);
			return resultMap;
		} catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}
	}
}
